import cn.xnatural.enet.server.dao.hibernate.Hibernate
import org.hibernate.Criteria

def dao = new Hibernate()
        .attr("ds.url", "jdbc:mysql://19.19.22.119:3306/kratos")
        .attr("ds.username", "tongdun")
        .attr("ds.password", "tongdun@2018");
try {
    dao.start();
    dao.doWork({sf ->
        sf.getCurrentSession()
                .createSQLQuery("select name, display_name, input_config, output_config from data_collector order by name")
                .setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP)
                .list().each {println(it.name)};
    }, null, null)
} finally {
    dao.stop()
}
return

//Map<String, String> props = new HashMap<>();
//props.put("url", "jdbc:mysql://19.19.22.119:3306/kratos");
//props.put("username", "tongdun");
//props.put("password", "tongdun@2018");
//DruidDataSource ds = (DruidDataSource) DruidDataSourceFactory.createDataSource(props);
//JdbcTemplate tpl = new JdbcTemplate(ds);
//Workbook wb = WorkbookFactory.create(new File("e:/tmp/xx.xlsx"));
//Sheet sheet = wb.getSheetAt(0);
//
//AtomicInteger rowCount = new AtomicInteger(0);
//tpl.query("select name, display_name, input_config, output_config from data_collector order by name", {rs, rowNum ->
//    String iName = rs.getString("display_name");
//    System.out.println("接口: " + iName);
//    JSONArray arr = JSON.parseArray(rs.getString("input_config"));
//
//    for (Object o : arr) {
//        JSONObject jo = (JSONObject) o;
//        String field = jo.getString("systemField");
//        Row row = sheet.createRow(rowCount.getAndIncrement());
//        row.createCell(0).setCellValue(iName);
//        row.createCell(1).setCellValue("入");
//        row.createCell(2).setCellValue(field);
//        tpl.query("select display_name from rule_field where name='" + field + "'", {rs1, rowNum1 ->
//            row.createCell(3).setCellValue(rs1.getString("display_name"));
//            return null;
//        });
//        // System.out.println(row.toString());
//    }
//    arr = JSON.parseArray(rs.getString("output_config"));
//    for (Object o : arr) {
//        JSONObject jo = (JSONObject) o;
//        String field = jo.getString("systemField");
//        if ("errorCode".equals(field)) continue;
//        Row row = sheet.createRow(rowCount.getAndIncrement());
//        row.createCell(0).setCellValue(iName);
//        row.createCell(1).setCellValue("出");
//        row.createCell(2).setCellValue(field);
//        tpl.query("select display_name, type, description from rule_field where name='" + field + "'", {rs1, rowNum1 ->
//            row.createCell(3).setCellValue(rs1.getString("display_name"));
//            if ("ENUM".equals(rs1.getString("type")) && StringUtils.isNotEmpty(rs1.getString("description"))) {
//                row.createCell(4).setCellValue(rs1.getString("description"));
//            }
//            return null;
//        });
//        // System.out.println(row);
//    }
//    rowCount.getAndIncrement();
//});
//ds.close();
//wb.write(new FileOutputStream(new File("e:/tmp/result.xlsx")));
//wb.close();